#include <stdio.h>

struct Student
{
    int num;
    char name[20];
    int age;
};

int main(int argc, char ** argv)
{
    struct Student stus[3] = {{1, "zhangsan", 12},{2, "lisi", 13},{3,"wangwu", 14}};
    //二进制的读写不会丢数据
    FILE *fp = fopen(argv[1], "wb+");
    for(int i = 0; i < 3; i++)
    {
        fwrite(&stus[i], 1, sizeof(struct  Student), fp);       //把信息写入
        fflush(fp);
    }
    struct Student temp;
    rewind(fp);
    fseek(fp, sizeof(struct Student), SEEK_CUR);        //移动指针到下一个结构体
    fread(&temp, 1, sizeof(struct Student), fp);        //读出信息
    printf("num = %d name = %s age = %d\n", temp.num, temp.name, temp.age);     //打印信息

    fclose(fp);

    return 0;
    

}